/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.game.wordpuzzle;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author AritomoAbe
 */
public class StartPlayAction implements GameAction {

    @Override
    public void processActionRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String gameId = request.getParameter("gameId");
        String userName = request.getParameter("userName");

        Game game = GameManager.getGameManager().getActiveGame(gameId);
        if (game != null && userName != null) {
            if (userName.equals(game.getOwnerName())) {
                game.splitAnswer();
            }

            User user = game.getUser(userName);

            PrintWriter out = response.getWriter();
            try {
                out.println(user.getAnswerPart());
            } finally {
                out.close();
            }
        }
    }
}
